/*
 * Copyright (C) 2011 CrystalRange
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.crystalrange.enterprise.service.impl;

import com.googlecode.genericdao.search.Search;
import com.googlecode.genericdao.search.SearchResult;
import java.util.Date;
import java.util.List;
import org.crystalrange.enterprise.dao.FiscalPeriodVariantDao;
import org.crystalrange.enterprise.model.FiscalPeriodVariant;
import org.crystalrange.enterprise.service.FiscalPeriodVariantService;
import org.crystalrange.model.User;
import org.crystalrange.service.UserService;

public class FiscalPeriodVariantServiceImpl implements FiscalPeriodVariantService {

    private FiscalPeriodVariantDao fiscalPeriodVariantDao;
    private UserService userService;

    public void setFiscalPeriodVariantDao(FiscalPeriodVariantDao fiscalPeriodVariantDao) {
        this.fiscalPeriodVariantDao = fiscalPeriodVariantDao;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }
    
    public FiscalPeriodVariant create(String username) {
        
        User currentUser = this.userService.findByUsername(username);  
        
        FiscalPeriodVariant fiscalPeriodVariant = new FiscalPeriodVariant();
        fiscalPeriodVariant.setCreatedBy(currentUser);
        fiscalPeriodVariant.setCreatedDate(new Date());
        
        return fiscalPeriodVariant;
    }
    
    public void save(FiscalPeriodVariant fiscalPeriodVariant, String username) {
        
        User currentUser = this.userService.findByUsername(username);  
        
        fiscalPeriodVariant.setUpdatedBy(currentUser);
        fiscalPeriodVariant.setUpdatedDate(new Date());
        
        this.fiscalPeriodVariantDao.save(fiscalPeriodVariant);
    }

    public void remove(FiscalPeriodVariant fiscalPeriodVariant) {
        this.fiscalPeriodVariantDao.remove(fiscalPeriodVariant);
    }

    public FiscalPeriodVariant find(Long id) {
        return this.fiscalPeriodVariantDao.find(id);
    }

    public List<FiscalPeriodVariant> findAll() {
        return this.fiscalPeriodVariantDao.findAll();
    }

    public SearchResult<FiscalPeriodVariant> searchAndCount(Search search) {
        return this.fiscalPeriodVariantDao.searchAndCount(search);
    }
    
    public List<FiscalPeriodVariant> search(Search search) {
        return this.fiscalPeriodVariantDao.search(search);
    }

    public FiscalPeriodVariant searchUnique(Search search) {
        return this.fiscalPeriodVariantDao.searchUnique(search);
    }
}
